<?php

/**
 * @author 
 * @copyright 2012
 */

require_once "include/facebook.php";
 
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
  'appId'  => FB_APP_ID,
  'secret' => FB_APP_SECRET,
));

$smarty->assign("facebook_app_id", FB_APP_ID);

/*
$facebook = new Facebook(array(
  'appId'  => '316878591712285',
  'secret' => 'c45d7129bc9888a8da335f279bc73fed',
));
$smarty->assign("facebook_app_id", '316878591712285');
*/

// Get User ID
if (isset($_SESSION['fb_'.FB_APP_ID.'_user_id'])){ 
  unset($_SESSION['fb_'.FB_APP_ID.'_user_id']);
}
if (!in_array($page, array('product', 'mechanic'))){
  $fbUserId = $facebook->getUser();
  // We may or may not have this data based on whether the user is logged in.
  //
  // If we have a $user id here, it means we know the user is logged into
  // Facebook, but we don't know if the access token is valid. An access
  // token is invalid if the user logged out of Facebook.
  //var_dump($user); exit();
  
  if ($fbUserId) {
    $res = $database->db_query("SELECT * FROM users WHERE user_fb_id=%d", $fbUserId);
    $user = $database->db_fetch_assoc($res); 
    $smarty->assign('fb_uid', $fbUserId);
    
    try {
      $likes = $facebook->api("/me/likes/229889220400100");
    	if (empty($likes['data'])){
    	  if ($page!='notlike') cheader('notlike.php');
    	}elseif ($page=='notlike') cheader('index.php');
    } catch (FacebookApiException $e) {
    }
    
  }else{
    $user = false;
    $smarty->assign('fb_uid', 0);
  }
}else{
  $user = false;
  $smarty->assign('fb_uid', 0);
}
?>